package com.joysuch.wwyt.bp.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joysuch.wwyt.bp.bean.BpHiddenDangerBean;
import com.joysuch.wwyt.bp.bean.BpTaskInvestigateBean;
import com.joysuch.wwyt.bp.bean.TaskListExcelBean;
import com.joysuch.wwyt.bp.bean.investigate.HdFieldConfigBean;
import com.joysuch.wwyt.bp.bean.investigate.SimpleRecordItem;
import com.joysuch.wwyt.bp.bean.investigate.TaskSearchBean;
import com.joysuch.wwyt.bp.bean.investigate.TaskSearchVo;
import com.joysuch.wwyt.bp.bean.investigate.vo.TaskListVo;
import com.joysuch.wwyt.bp.bean.investigate.vo.TaskVo;
import com.joysuch.wwyt.bp.bean.vo.TaskStatiUserVo;
import com.joysuch.wwyt.bp.entity.BpInvestigateTaskAssign;
import com.joysuch.wwyt.bp.entity.bean.SimpleInvTaskBean;
import com.joysuch.wwyt.bp.entity.investigate.BpInvestigateTask;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.joysuch.wwyt.bp.entity.dto.CheckRecordDto;
import com.joysuch.wwyt.core.bean.SimpleIdMapping;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author heqifeng
 * @since 2022-04-07
 */
@Repository
public interface BpInvestigateTaskMapper extends BaseMapper<BpInvestigateTask> {

    void batchInsert(@Param("list") List<BpInvestigateTask> taskList);

    Page<TaskListVo> selectHistoryTaskPage(Page<BpInvestigateTask> page, TaskSearchBean search);

    Long selectHistoryTaskCount(@Param("search") TaskSearchBean search);

    Page<TaskListVo> selectHistoryNewTaskPage(Page<BpInvestigateTask> page, TaskSearchBean search);

    List<TaskListExcelBean> selectHistorys(Page<BpInvestigateTask> page, TaskSearchBean search);

    Long selectHistoryNewTaskCount(@Param("search") TaskSearchBean search);

    Long selectTaskRecordCountAll(@Param("tenentId") Long tenentId, @Param("orgCode") String orgCode, @Param("authDepartIds")List<Long> authDepartIds);

    CheckRecordDto selectRecordDetail(Long taskId, boolean isHistory);

    List<TaskListExcelBean> selectCheckRecordDetail(@Param("taskIds") List<Long> taskIds,@Param("isHistory") Boolean isHistory);

    Page<TaskStatiUserVo> getDetailGroupByUser(Page<TaskStatiUserVo> page,@Param("search") TaskSearchBean search);

    TaskStatiUserVo getAllGraphical(@Param("search") TaskSearchBean search);

    TaskStatiUserVo getTaskGraphical(@Param("search") TaskSearchBean search, @Param("hdFieldConfig") HdFieldConfigBean hdFieldConfig);

    List<SimpleRecordItem> selectSimpleItem(@Param("list") List<Long> taskIds);

    int changeStatusByIds(@Param("list") List<Long> taskIds, @Param("status") String status, @Param("updateTime") Date updateTime);

    List<SimpleInvTaskBean> selectByDeadLine(@Param("currDate") Date currDate);

    List<SimpleInvTaskBean> selectByCheckDate(@Param("currDate") Date currDate);

    List<SimpleIdMapping> getPlanIdByTaskIds(@Param("list") List<Long> list);

    Long exitsId(Long id);

    List<Long> exitsIds(@Param("ids") List<Long> list);

    List<Long> exitsHisIds(@Param("ids") List<Long> list);

    /**
     * 任务、记录、记录详情数据迁移到历史表
     */
    List<Long> getIdByDate(@Param("date") Date date);
    List<Long> getRecordIdByTaskIds(@Param("list") Collection<Long> list);

    List<Long> getRecordIdByTaskId(@Param("taskId") Long taskId);

    List<Long> getRecordItemIdByRecordIds(@Param("list") Collection<Long> list);

    long copyTaskToHistoryByIds(@Param("list") Collection<Long> list);
    long copyRecordToHistoryByIds(@Param("list") Collection<Long> list);
    long copyRecordItemToHistoryByIds(@Param("list") Collection<Long> list);

    long deleteTaskByIds(@Param("list") Collection<Long> list);
    long deleteRecordByIds(@Param("list") Collection<Long> list);
    long deleteRecordItemByIds(@Param("list") Collection<Long> list);

    BpInvestigateTask findByPlanId(@Param("planId")Long planId);

    List<Long> findByPlanIdAndId(Long planId, Long id);

    Page<BpTaskInvestigateBean> getTroubleshootingStatistics(Page<TaskStatiUserVo> page, @Param("search") TaskSearchBean search);

    BpTaskInvestigateBean getBpTaskInvestigateBean(@Param("search") TaskSearchBean search);

    Page<BpHiddenDangerBean> getBpHiddenDangerBeanStatistics(Page<TaskStatiUserVo> page, @Param("search")  TaskSearchBean search, @Param("bizName")  String bizName, @Param("dateName")  String dateName,
                                                             @Param("departName") String departName, @Param("reportTime") String reportTime, @Param("verificationName") String verificationName,@Param("states") List<String> states);

    BpHiddenDangerBean getBpHiddenDangerBean(TaskSearchBean search,  @Param("bizName")  String bizName, @Param("dateName")  String dateName,
                                             @Param("departName") String departName, @Param("reportTime") String reportTime, @Param("verificationName") String verificationName,@Param("states") List<String> states);

    List<Long> exitsHisRecordIds(@Param("ids") List<Long> recordIds);

    List<Long> exitsHisRecordItemIds(@Param("ids")List<Long> recordItemIds);

    List<Long> findUserIds(Long taskId);

    List<TaskStatiUserVo> getTaskDetailGroupByUser(@Param("search") TaskSearchBean search, @Param("hdFieldConfig") HdFieldConfigBean hdFieldConfig);
    Page<TaskVo> findTaskListPage(Page<BpInvestigateTask> page, @Param("search")TaskSearchVo search);

    List<Long> findByPlanIds(@Param("ids")List<Long> ids);

    long deleteAssignByTaskIds(@Param("taskIds")List<Long> taskIds);

    List<BpInvestigateTaskAssign> findAssigns(@Param("taskIds")List<Long> taskIds);

    void updateTaskCount(@Param("summaryId")Long summaryId, @Param("taskCount")Integer taskCount);

    long deleteAssignByIds(@Param("ids")List<Long> ids);

    List<BpInvestigateTaskAssign> findAssignsById(@Param("ids")List<Long> ids);

    Integer findAssignsCount(@Param("taskId") Long taskId);

    BpInvestigateTask findOne(@Param("planId") Long planId, @Param("checkDate") Date checkDate, @Param("deadline") Date deadline);

    List<Long> findTasks(@Param("time") Date time);

    List<BpInvestigateTask> findTodayTask(@Param("planId") Long planId);

    List<Long> selectByDistrictId(@Param("districtId") Long districtId, @Param("userId") Long userId);

    Page<TaskListVo> selectTodayTaskPage(Page<BpInvestigateTask> page, TaskSearchBean search);

    Long selectTodayTaskCount(@Param("search") TaskSearchBean search);

    long copyHisRecordToYearRecordByIds(@Param("recordIds") List<Long> recordIds, @Param("year") String year);

    void deleteHisRecordByIds(@Param("recordIds") List<Long> recordIds);

    List<Long> getHisRecordItemIdByRecordIds(@Param("recordIds") List<Long> recordIds);

    long copyHisRecordItemToYearRecordItemByIds(@Param("recordItemIds") List<Long> recordItemIds, @Param("year") String year);

    void deleteHisRecordItemByIds(@Param("recordItemIds") List<Long> recordItemIds);

    boolean deleteTaskById(@Param("id") Long id);

}
